package com.yan_jiu_sheng.LeetCodeHot100.AC;

import java.util.HashMap;
import java.util.List;

/**
 * https://leetcode.cn/problems/intersection-of-two-linked-lists/description/?envType=study-plan-v2&envId=top-100-liked
 * 通过
 *
 * @author yulongTian
 * @create 2024-05-29 14:32
 */
public class Test22 {
    public static void main(String[] args) {

    }


    private class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
            next = null;
        }
    }

    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        HashMap<Integer, Integer> hashMap = new HashMap<>();
        ListNode pointer = headA;

        while (pointer != null) {
            hashMap.put(pointer.hashCode(), 1);
            pointer = pointer.next;
        }
        pointer = headB;
        while (pointer != null) {
            if (hashMap.containsKey(pointer.hashCode())) {
                return pointer;
            }
            pointer = pointer.next;
        }
        return null;
    }


}
